package main

import (
	"fmt"
	"io"
	"log"
	"net"
	"strings"
)

func process(tcpConn *net.TCPConn) {
	defer tcpConn.Close()
	var buff []byte
	for {
		b := make([]byte, 1024)
		_, err := tcpConn.Read(b)
		if err != nil {
			if err == io.EOF {
				break
			}
			fmt.Println("读取数据失败", err)
			return
		}
		buff = append(buff, b...)
		str := string(buff)
		contains := strings.Contains(str, "\r\n\r\n")
		if contains {
			split := strings.Split(str, "\r\n\r\n")
			for _, v := range split {
				fmt.Println(v)
				fmt.Println("==============================")
			}
		}
	}
}
func main() {
	tcpListener, err := net.ListenTCP("tcp", &net.TCPAddr{
		Port: 8000,
	})
	if err != nil {
		log.Fatalln("服务器启动失败", err)
		return
	}
	defer tcpListener.Close()
	for {
		tcpConn, err := tcpListener.AcceptTCP()
		if err != nil {
			fmt.Println("接收连接失败", err)
			continue
		}
		go process(tcpConn)
	}
}
